//
//  YLAExtension.swift
//  Your Lover AI
//
//  Created by 阿忠 on 2024/6/21.
//

import Foundation
import UIKit

extension UIColor {
    
    convenience init(hex: String) {
        let scanner = Scanner(string: hex) // 直接创建 Scanner 实例
        var rgbValue: UInt64 = 0
        
        guard scanner.scanHexInt64(&rgbValue) && rgbValue <= UInt64.max else {
            self.init(white: 0, alpha: 1.0)
            return
        }
        
        let r = CGFloat((rgbValue & 0xff0000) >> 16) / 255.0
        let g = CGFloat((rgbValue & 0x00ff00) >> 8) / 255.0
        let b = CGFloat(rgbValue & 0x0000ff) / 255.0
        self.init(red: r, green: g, blue: b, alpha: 1.0)
    }
    
    // ... 其他方法 ...
}
